package com.aurora.blog.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aurora.common.log.annotation.Log;
import com.aurora.common.log.enums.BusinessType;
import com.aurora.common.security.annotation.RequiresPermissions;
import com.aurora.blog.domain.BlogLikes;
import com.aurora.blog.service.IBlogLikesService;
import com.aurora.common.core.web.controller.BaseController;
import com.aurora.common.core.web.domain.AjaxResult;
import com.aurora.common.core.utils.poi.ExcelUtil;
import com.aurora.common.core.web.page.TableDataInfo;

/**
 * 点赞Controller
 * 
 * @author aurora
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/blogLikes")
public class BlogLikesController extends BaseController
{
    @Autowired
    private IBlogLikesService blogLikesService;

    /**
     * 查询点赞列表
     */
    @RequiresPermissions("blog:blogLikes:list")
    @GetMapping("/list")
    public TableDataInfo list(BlogLikes blogLikes)
    {
        startPage();
        List<BlogLikes> list = blogLikesService.selectBlogLikesList(blogLikes);
        return getDataTable(list);
    }

    /**
     * 导出点赞列表
     */
    @RequiresPermissions("blog:blogLikes:export")
    @Log(title = "点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogLikes blogLikes)
    {
        List<BlogLikes> list = blogLikesService.selectBlogLikesList(blogLikes);
        ExcelUtil<BlogLikes> util = new ExcelUtil<BlogLikes>(BlogLikes.class);
        util.exportExcel(response, list, "点赞数据");
    }

    /**
     * 获取点赞详细信息
     */
    @RequiresPermissions("blog:blogLikes:query")
    @GetMapping(value = "/{likeId}")
    public AjaxResult getInfo(@PathVariable("likeId") Long likeId)
    {
        return success(blogLikesService.selectBlogLikesByLikeId(likeId));
    }

    /**
     * 新增点赞
     */
    @RequiresPermissions("blog:blogLikes:add")
    @Log(title = "点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogLikes blogLikes)
    {
        return toAjax(blogLikesService.insertBlogLikes(blogLikes));
    }

    /**
     * 修改点赞
     */
    @RequiresPermissions("blog:blogLikes:edit")
    @Log(title = "点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogLikes blogLikes)
    {
        return toAjax(blogLikesService.updateBlogLikes(blogLikes));
    }

    /**
     * 删除点赞
     */
    @RequiresPermissions("blog:blogLikes:remove")
    @Log(title = "点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{likeIds}")
    public AjaxResult remove(@PathVariable Long[] likeIds)
    {
        return toAjax(blogLikesService.deleteBlogLikesByLikeIds(likeIds));
    }
}
